package com.blog.check.check;

import com.blog.check.resultenum.ProfileChkRsEnum;
import com.blog.check.resultenum.UserChkRsEnum;
import com.blog.dao.domain.ProfileDO;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;


/**
 * 个人信息处理检查
 *
 * @author HCK
 *
 */
@Service
public class ProfileCheck extends BaseCheck {

    /**
     * 检查更新
     *
     * @param id id
     * @return {@link CheckResult}
     */
    public CheckResult checkUpdate(String id){
        // Non-logical check for update
        return checkUpdateNonLogical(id);
    }


    private CheckResult checkUpdateNonLogical(String id) {

        if (getUsername() == null){
            return CheckResult.failure(UserChkRsEnum.USER_IS_NOT_LOGIN);
        }
        ProfileDO profileDO = profileDAO.get(id);
        if(ObjectUtils.isEmpty(profileDO)){
            return CheckResult.failure(ProfileChkRsEnum.ILLEGAL_ID_NOT_EXIST,id);
        }
        return CheckResult.success();
    }
}
